(function() {
    angular.module('BlurAdmin.pages.Journal')
        .controller('JournalCtrl', JournalCtrl);

    function JournalCtrl($scope, $openModal, $myconfig, $http, $datepicker, tongxin, $mydialog) {
        $scope.format = "yyyy/MM/dd";
        $scope.altInputFormats = ['yyyy-MM-dd-HH'];
        $scope.dat = {
            dat1: $datepicker.dataNew(),
            dat2: $datepicker.dataNew(),
        };
        $scope.dat.dat1.date_ = '';
        $scope.dat.dat2.date_ = '';

        $scope.dianji = function() {
            console.log(1111);
        }

        //分页
        $scope.items_page = 5; //每页多少条
        $scope.maxSize = 5; //底下显示几个页
        $scope.bigTotalItems = 50; //一共多少数据
        $scope.bigCurrentPage = 1; //当前是第几页



        $scope.pageChanged = function(val) {
            var Page_num = val //选中的页面数
            $scope.search_opt.page = val;
            Search_list();
        };

        $scope.search_opt = {
            "limit": 10,
            "page": 1,
            "operation": "",
            "username": "",
            "describe": "",
            "type": "", //业务模块
            "start_time": "",
            "end_time": ""
        }
        var opt = {};

        $scope.Search = function() { //获取用户理疗记录统计数据
            var data1 = document.getElementById("dat1") ? document.getElementById("dat1").value : null;
            var data2 = document.getElementById("dat2") ? document.getElementById("dat2").value : null;
            opt = $scope.search_opt;
            opt.start_time = data1;
            opt.end_time = data2;
            $http.get($myconfig.api.systemlogs_count_b, { params: opt }).then(function(res) {
                console.log(res.data.data);
                $scope.bigTotalItems = res.data.data;
                Search_list();
            })
        }

        function Search_list() { //获取用户理疗记录统计数据
            $http.get($myconfig.api.systemlogs_list_b, { params: opt }).then(function(res) {
                if (res.data.success) {
                    for (var i = 0; i < res.data.data.length; i++) { //添加条数属性
                        res.data.data[i].num = (($scope.search_opt.page - 1) * $scope.search_opt.limit) + i + 1;
                    }
                    $scope.list_data = res.data.data;
                }
                console.log($scope.list_data);
            })
        }

        $scope.Search();

        //删除
        var id = null;
        $scope.delete_val = function(val) {
            $http.post($myconfig.api.systemlogs_remove, { id: id }).then(function(res) {
                if (res.data.success) {
                    $mydialog.success('删除成功');
                    Search_list();
                } else {
                    $mydialog.fail(res.data.data)
                }
            });

        }

        function my_callback(val) {
            if (val == true) {
                $scope.delete_val()
            }
        };

        $scope.fn_delete = function(val) {
            id = val;
            $mydialog.inquiry('确定要删除吗？', my_callback)
        };







    }
})();